package org.gwtmultipage.sample.client;

import hr.fer.zemris.rznu.model.dto.user.AddressDTO;
import hr.fer.zemris.rznu.model.dto.user.PersonalUserInfoDTO;
import hr.fer.zemris.rznu.model.dto.user.UserDTO;

import org.gwtmultipage.client.UrlPatternEntryPoint;

import org.gwtmultipage.sample.client.RegisterService;
import org.gwtmultipage.sample.client.RegisterServiceAsync;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.MenuItemSeparator;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.datepicker.client.DateBox;
import com.google.gwt.user.datepicker.client.DateBox.DefaultFormat;
import com.google.gwt.i18n.client.DateTimeFormat;
import java.util.Date;


@UrlPatternEntryPoint("Register.html(\\\\?.*)?")
public class Register implements EntryPoint {
	
	private RootPanel wrapper;
	private VerticalPanel preContainer;
	private LayoutPanel container;
	private FlowPanel header;
	private FlowPanel banner;
	private FlowPanel content;
	private FlowPanel footer;
	private FlowPanel topMenu;
	private MenuBar menuBar;
	private VerticalPanel loginContainer;
	private MenuItem naslovnica;
	private MenuItemSeparator separator;
	private MenuItem ponuda;
	private MenuItemSeparator separator_1;
	private MenuItem rezultati;
	private MenuItemSeparator separator_2;
	private MenuItem statistika;
	private FlowPanel content1;
	private FlowPanel contentTop;
	private Label labelFooter;
	private HorizontalPanel login;
	private Image imageHr;
	private Image imageEng;	
	private FlexTable flexTable_1;
	private Label labelName;
	private TextBox textBoxName;
	private Label labelUsername;
	private TextBox textBoxUsername;
	private ScrollPanel scrollPanel;
	private Label label_2;
	private Label labelMiddleName;
	private TextBox textBoxMiddleName;
	private Label labelEmail;
	private TextBox textBoxEmail;
	private Label labelSurname;
	private TextBox textBoxSurname;
	private Label labelConfEmail;
	private TextBox textBoxConfEmail;
	private Label labelDateOfBirth;
	private Label labelPassword;
	private PasswordTextBox textBoxPassword;
	private Label labelStreet;
	private TextBox textBoxStreet;
	private Label labelConfPassword;
	private PasswordTextBox textBoxConfPassword;
	private Label labelNumber;
	private TextBox textBoxNumber;
	private CheckBox checkBox;
	private Label labelPostnumber;
	private TextBox textBoxPostnumber;
	private Button registerButton;
	private Label labelTown;
	private TextBox textBoxTown;
	private Label labelCountry;
	private ListBox comboBox;
	private DateBox dateBox;
	
	UserDTO newUser = new UserDTO();
	PersonalUserInfoDTO personalUserInfo = new PersonalUserInfoDTO();
	AddressDTO address = new AddressDTO();
	
	private BettingConstants constants = GWT.create(BettingConstants.class);
	private BettingMessages messages = GWT.create(BettingMessages.class);

	private static final String SERVER_ERROR = "An error occurred while "
		+ "attempting to contact the server. Please check your network "
		+ "connection and try again.";
	
	private final RegisterServiceAsync registerService = GWT.create(RegisterService.class);
	private final InternationalizationServiceAsync interService = GWT.create(InternationalizationService.class);
	
	
	public void onModuleLoad() {


		wrapper = RootPanel.get();
		wrapper.setStyleName("gwt-Template-wrapper");
		wrapper.setSize("100%", "700px");
		
		preContainer = new VerticalPanel();
		preContainer.setBorderWidth(0);
		preContainer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		wrapper.add(preContainer, 0, 0);
		preContainer.setSize("100%", "700 px");
		
		container = new LayoutPanel();
		preContainer.add(container);
		preContainer.setCellHorizontalAlignment(container, HasHorizontalAlignment.ALIGN_CENTER);
		container.setStyleName("gwt-Template-container");
		container.setSize("960", "700 px");
		
		header = new FlowPanel();
		header.setStyleName("gwt-Template-header");
		container.add(header);
		header.setWidth("958");
		container.setWidgetLeftWidth(header, 0.0, Unit.PX, 964.0, Unit.PX);
		container.setWidgetTopHeight(header, 0.0, Unit.PX, 125.0, Unit.PX);
		
		loginContainer = new VerticalPanel();
		loginContainer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		loginContainer.setStyleName("gwt-Template-topmenu");
		header.add(loginContainer);
		
		login = new HorizontalPanel();
		login.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		login.setSize("700", "35");
		loginContainer.add(login);
				
		topMenu = new FlowPanel();
		topMenu.setStyleName("gwt-Template-login");
		header.add(topMenu);
		
		imageHr = new Image("images/hrvatski.gif");
		topMenu.add(imageHr);
		imageHr.setStyleName("gwt-ImageHr");
		imageHr.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				interService.currentLanguage("hr", new AsyncCallback<Void>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("Error " + caught.getMessage());
						
					}

					@Override
					public void onSuccess(Void result) {
						Window.open("http://127.0.0.1:8888/Register.html?gwt.codesvr=127.0.0.1:9997?locale=hr", "_self", null);
						
					}});
			}
		});
		
		imageEng = new Image("images/engleski.gif");
		topMenu.add(imageEng);
		imageEng.setStyleName("gwt-ImageHr");
		imageEng.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				interService.currentLanguage("eng", new AsyncCallback<Void>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("Error " + caught.getMessage());
						
					}

					@Override
					public void onSuccess(Void result) {
						Window.open("http://127.0.0.1:8888/Register.html?gwt.codesvr=127.0.0.1:9997", "_self", null);
						
					}});
			}
		});
		
		menuBar = new MenuBar(false);
		menuBar.setAnimationEnabled(true);
		topMenu.add(menuBar);
		menuBar.setSize("360", "22");
		
		naslovnica = new MenuItem(constants.home(), false, new Command() {
			public void execute() {
				interService.checkCurrentLanguage(new AsyncCallback<String>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("Error " + caught.getMessage());
						
					}

					@Override
					public void onSuccess(String result) {
						//Window.alert(result);
						if (result.equals("eng") || result.equals("null")) {
							Window.open("http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997", "_self", null);
						}
						else if(result.equals("hr")) {
							Window.open("http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997?locale=hr", "_self", null);
						}
						
					}});
			}
		});
		menuBar.addItem(naslovnica);
		naslovnica.setWidth("90");
		
		separator = new MenuItemSeparator();
		menuBar.addSeparator(separator);
		
		ponuda = new MenuItem(constants.bets(), false, new Command() {
			public void execute() {
				interService.checkCurrentLanguage(new AsyncCallback<String>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("Error " + caught.getMessage());
						
					}

					@Override
					public void onSuccess(String result) {
						if(result.equals("eng") || result.equals("null")) {
							Window.open("http://127.0.0.1:8888/Bets.html?gwt.codesvr=127.0.0.1:9997", "_self", null);
						}
						else if(result.equals("hr")) {
							Window.open("http://127.0.0.1:8888/Bets.html?gwt.codesvr=127.0.0.1:9997?locale=hr", "_self", null);
						}
						
					}});
			}
		});
		menuBar.addItem(ponuda);
		ponuda.setWidth("90");
		
		separator_1 = new MenuItemSeparator();
		menuBar.addSeparator(separator_1);
		
		rezultati = new MenuItem(constants.results(), false, new Command() {
			public void execute() {
				interService.checkCurrentLanguage(new AsyncCallback<String>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("Error " + caught.getMessage());
						
					}

					@Override
					public void onSuccess(String result) {
						if(result.equals("eng") || result.equals("null")) {
							Window.open("http://127.0.0.1:8888/Results.html?gwt.codesvr=127.0.0.1:9997", "_self", null);
						}
						else if(result.equals("hr")) {
							Window.open("http://127.0.0.1:8888/Results.html?gwt.codesvr=127.0.0.1:9997?locale=hr", "_self", null);
						}
						
					}});
			}
		});
		menuBar.addItem(rezultati);
		rezultati.setWidth("90");
		
		separator_2 = new MenuItemSeparator();
		menuBar.addSeparator(separator_2);
		
		statistika = new MenuItem(constants.statistic(), false, new Command() {
			public void execute() {
				interService.checkCurrentLanguage(new AsyncCallback<String>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("Error " + caught.getMessage());
						
					}

					@Override
					public void onSuccess(String result) {
						if(result.equals("eng") || result.equals("null")) {
							Window.open("http://127.0.0.1:8888/Statistic.html?gwt.codesvr=127.0.0.1:9997", "_self", null);
						}
						else if(result.equals("hr")) {
							Window.open("http://127.0.0.1:8888/Statistic.html?gwt.codesvr=127.0.0.1:9997?locale=hr", "_self", null);
						}
						
					}});
			}
		});
		menuBar.addItem(statistika);
		statistika.setWidth("90");
		
		banner = new FlowPanel();
		banner.setStyleName("gwt-Template-banner");
		container.add(banner);
		banner.setSize("938", "195");
		container.setWidgetLeftWidth(banner, 11.0, Unit.PX, 938.0, Unit.PX);
		container.setWidgetTopHeight(banner, 106.0, Unit.PX, 250.0, Unit.PX);
		
		content = new FlowPanel();
		content.setSize("956", "100%");
		content.setStyleName("gwt-Template-Content");
		container.add(content);
		container.setWidgetLeftWidth(content, 0.0, Unit.PX, 960.0, Unit.PX);
		container.setWidgetTopHeight(content, 309.0, Unit.PX, 300.0, Unit.PX);
		
		content1 = new FlowPanel();
		content.add(content1);
		content1.setSize("", "100%");
		content1.setStyleName("gwt-Template-Content1");
		
		flexTable_1 = new FlexTable();
		content1.add(flexTable_1);
		flexTable_1.setSize("794", "220");
		
		labelName = new Label(constants.name());
		labelName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(0, 0, labelName);
		labelName.setSize("100", "21");
		
		textBoxName = new TextBox();
		textBoxName.setSize("160", "20");
		flexTable_1.setWidget(0, 1, textBoxName);
		
		labelUsername = new Label(constants.username());
		labelUsername.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		labelUsername.setDirectionEstimator(true);
		flexTable_1.setWidget(0, 2, labelUsername);
		labelUsername.setWidth("120");
		
		textBoxUsername = new TextBox();
		textBoxUsername.setSize("160", "20");
		flexTable_1.setWidget(0, 3, textBoxUsername);
		
		scrollPanel = new ScrollPanel();
		flexTable_1.setWidget(0, 8, scrollPanel);
		scrollPanel.setSize("280", "110");
		
		label_2 = new Label(constants.terms());
		scrollPanel.setWidget(label_2);
		label_2.setSize("100%", "100%");
		
		labelMiddleName = new Label(constants.middleName());
		labelMiddleName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(1, 0, labelMiddleName);
		labelMiddleName.setWidth("100");
		
		textBoxMiddleName = new TextBox();
		textBoxMiddleName.setSize("160", "20");
		flexTable_1.setWidget(1, 1, textBoxMiddleName);
		
		labelEmail = new Label(constants.email());
		labelEmail.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		labelEmail.setDirectionEstimator(true);
		flexTable_1.setWidget(1, 2, labelEmail);
		labelEmail.setSize("120", "21");
		
		textBoxEmail = new TextBox();
		textBoxEmail.setSize("160", "20");
		flexTable_1.setWidget(1, 3, textBoxEmail);
		
		labelSurname = new Label(constants.surname());
		labelSurname.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(2, 0, labelSurname);
		labelSurname.setSize("100", "21");
		
		textBoxSurname = new TextBox();
		textBoxSurname.setSize("160", "20");
		flexTable_1.setWidget(2, 1, textBoxSurname);
		
		labelConfEmail = new Label(constants.confirmEmail());
		labelConfEmail.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		labelConfEmail.setDirectionEstimator(true);
		flexTable_1.setWidget(2, 2, labelConfEmail);
		labelConfEmail.setWidth("120");
		
		textBoxConfEmail = new TextBox();
		textBoxConfEmail.setSize("160", "20");
		flexTable_1.setWidget(2, 3, textBoxConfEmail);
		
		labelDateOfBirth = new Label(constants.dateOfBirth());
		labelDateOfBirth.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(3, 0, labelDateOfBirth);
		labelDateOfBirth.setWidth("100");
		
		dateBox = new DateBox();
		dateBox.setValue(new Date(587071307645L));
		dateBox.setSize("160", "20");
		dateBox.setFormat(new DefaultFormat(DateTimeFormat.getFormat("d M y")));
		flexTable_1.setWidget(3, 1, dateBox);
		
		
		labelPassword = new Label(constants.password());
		labelPassword.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		labelPassword.setDirectionEstimator(true);
		flexTable_1.setWidget(3, 2, labelPassword);
		labelPassword.setWidth("120");
		
		textBoxPassword = new PasswordTextBox();
		textBoxPassword.setSize("160", "20");
		flexTable_1.setWidget(3, 3, textBoxPassword);
		
		labelStreet = new Label(constants.street());
		labelStreet.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(4, 0, labelStreet);
		labelStreet.setWidth("100");
		
		textBoxStreet = new TextBox();
		textBoxStreet.setSize("160", "20");
		flexTable_1.setWidget(4, 1, textBoxStreet);
		
		labelConfPassword = new Label(constants.confirmPassword());
		labelConfPassword.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		labelConfPassword.setDirectionEstimator(true);
		flexTable_1.setWidget(4, 2, labelConfPassword);
		labelConfPassword.setSize("120", "21");
		
		textBoxConfPassword = new PasswordTextBox();
		textBoxConfPassword.setSize("160", "20");
		flexTable_1.setWidget(4, 3, textBoxConfPassword);
		
		labelNumber = new Label(constants.streetNumber());
		labelNumber.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(5, 0, labelNumber);
		labelNumber.setWidth("100");
		
		textBoxNumber = new TextBox();
		textBoxNumber.setSize("160", "20");
		flexTable_1.setWidget(5, 1, textBoxNumber);
		
		labelPostnumber = new Label(constants.postNumber());
		labelPostnumber.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(6, 0, labelPostnumber);
		labelPostnumber.setWidth("100");
		
		textBoxPostnumber = new TextBox();
		textBoxPostnumber.setSize("160", "20");
		flexTable_1.setWidget(6, 1, textBoxPostnumber);
		
		checkBox = new CheckBox(constants.iAcceptTheTermsOfService());
		checkBox.setHeight("18");
		flexTable_1.setWidget(6, 8, checkBox);
		
		labelTown = new Label(constants.town());
		labelTown.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(7, 0, labelTown);
		labelTown.setWidth("100");
		
		textBoxTown = new TextBox();
		textBoxTown.setSize("160", "20");
		flexTable_1.setWidget(7, 1, textBoxTown);
		
		registerButton = new Button(constants.register());
		flexTable_1.setWidget(7, 8, registerButton);
		flexTable_1.getFlexCellFormatter().setRowSpan(7, 8, 2);
		flexTable_1.getFlexCellFormatter().setRowSpan(0, 8, 5);
		
		labelCountry = new Label(constants.country());
		labelCountry.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		flexTable_1.setWidget(8, 0, labelCountry);
		labelCountry.setWidth("100");
		
		comboBox = new ListBox();
		comboBox.addItem(constants.australia());
		comboBox.addItem(constants.bosnia());
		comboBox.addItem(constants.canada());
		comboBox.addItem(constants.croatia());
		comboBox.addItem(constants.france());
		comboBox.addItem(constants.germany());
		comboBox.addItem(constants.newZeland());
		comboBox.addItem(constants.unitedKingdom());
		comboBox.addItem(constants.unitedStates());
		comboBox.setSelectedIndex(3);
		comboBox.setSize("160", "");
		flexTable_1.setWidget(8, 1, comboBox);
		FlexTableHelper.fixRowSpan(flexTable_1);
					
		contentTop = new FlowPanel();
		contentTop.setStyleName("gwt-Template-ContentTop");
		content.add(contentTop);
		
		footer = new FlowPanel();
		footer.setStyleName("gwt-Template-footer");
		container.add(footer);
		container.setWidgetLeftWidth(footer, 0.0, Unit.PX, 960.0, Unit.PX);
		container.setWidgetTopHeight(footer, 609.0, Unit.PX, 80.0, Unit.PX);
		
		labelFooter = new Label(constants.course() + " | Copyright \u00A9 2010 | VirtualBetting");
		footer.add(labelFooter);
		
		textBoxName.selectAll();
		
		
		
		////////////////////////////////////////////////////
		// Create the popup dialog box
		final DialogBox dialogBox = new DialogBox();
		dialogBox.setText("REGISTRATION WINDOW");
		dialogBox.setAnimationEnabled(true);
		final Button closeButton = new Button("Close");
		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");
		final HTML serverResponseLabel = new HTML();
		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
		dialogVPanel.add(serverResponseLabel);
		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
		dialogVPanel.add(closeButton);
		dialogBox.setWidget(dialogVPanel);
		
		// Add a handler to close the DialogBox
		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				dialogBox.hide();
				interService.checkCurrentLanguage(new AsyncCallback<String>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("Error " + caught.getMessage());
						
					}

					@Override
					public void onSuccess(String result) {
						//Window.alert(result);
						if (result.equals("eng") || result.equals("null")) {
							Window.open("http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997", "_self", null);
						}
						else if(result.equals("hr")) {
							Window.open("http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997?locale=hr", "_self", null);
						}
						
					}});
			}
		});
		
		// Create a handler for the sendButton and nameField
		class MyHandler implements ClickHandler {
			/**
			 * Fired when the user clicks on the sendButton.
			 */
			public void onClick(ClickEvent event) {
				
				if(checkFields()){
				sendUserToServer();
				}
			}
			
			/**
			 * Send the UserDTO from the client to the server and wait for a response.
			 */
			private void sendUserToServer() {
				
				createObject();
				
				registerButton.setEnabled(false);
				serverResponseLabel.setText("");
				registerService.registerUser(newUser,
						new AsyncCallback<String>() {
							public void onFailure(Throwable caught) {
								Window.alert(SERVER_ERROR);
							}

							public void onSuccess(String result) {
								dialogBox.setText("REGISTRATION WINDOW");
								serverResponseLabel.setHTML(result);
								dialogBox.center();
								closeButton.setFocus(true);
								
							}
						});
			}
			}
		// Add a handler to send the User to the server
		MyHandler handler = new MyHandler();
		registerButton.addClickHandler(handler);
	}

	public void createObject(){
		
		personalUserInfo.setFirstName(textBoxName.getText());
		
		personalUserInfo.setMiddleName(textBoxMiddleName.getText());
		
		personalUserInfo.setLastName(textBoxSurname.getText());
	
		personalUserInfo.setEmail(textBoxEmail.getText());
		
		personalUserInfo.setDateOfBirth(dateBox.getValue());
		
		address.setAddress(textBoxStreet.getText());
		
		address.setAddressNumber(textBoxNumber.getText());
		
		address.setPostNumber(textBoxPostnumber.getText());
		
		address.setTown(textBoxTown.getText());
		
		address.setCountry(comboBox.getItemText(comboBox.getSelectedIndex()));
		
		newUser.setUsername(textBoxUsername.getText());

		newUser.setPassword(textBoxPassword.getText());
	
		personalUserInfo.setAddress(address);
		
		newUser.setPersonalUserInfoDTO(personalUserInfo);
		
	}
	
	public boolean checkFields (){
		boolean check = true;
		String alertText = "ERROR, please fill the fields correctly:\n";
		
		if(textBoxName.getText().matches("[a-zA-Z]+") == false){
			check = false;
			alertText += "\n*Name"; 
		}
			
		if(textBoxMiddleName.getText().matches("[a-zA-Z]*") == false){
			check = false;
			alertText += "\n*Middle Name";
		}
		
		if(textBoxSurname.getText().matches("[a-zA-Z]+") == false){
			check = false;
			alertText += "\n*Surname";
		}
		
		if(textBoxEmail.getText().matches("[a-z0-9._-]+@[a-z0-9.-]+.[a-z]{2,4}") == false){
			check = false;
			alertText += "\n*Email";
		}
		
		if(textBoxConfEmail.getText().matches("[a-z0-9._-]+@[a-z0-9.-]+.[a-z]{2,4}") == false){
			check = false;
			alertText += "\n*Confirm Email";
		}
		
		if(textBoxConfEmail.getText().equals(textBoxEmail.getText()) == false){
			check = false;
			alertText += "\n*Emails are not equal";
		}
		
		if(textBoxStreet.getText().matches("[a-zA-Z ]+") == false){
			check = false;
			alertText += "\n*Street";
		}
		
		if(textBoxNumber.getText().matches("[0-9]+") == false){
			check = false;
			alertText += "\n*Number";
		}
		
		if(textBoxPostnumber.getText().matches("[0-9]+") == false){
			check = false;
			alertText += "\n*Postnumber";
		}
		
		if(textBoxTown.getText().matches("[a-zA-Z ]+") == false){
			check = false;
			alertText += "\n*Town";
		}
		
		if(textBoxPassword.getText().matches("\\w+") == false){
			check = false;
			alertText += "\n*Password";
		}
		
		if(textBoxPassword.getText().length() < 4){
			check = false;
			alertText += "\n*Password has to be at least 4 characters long";
		}
		
		if(textBoxConfPassword.getText().matches("\\w+") == false){
			check = false;
			alertText += "\n*Confirm Password";
		}
		
		if(textBoxConfPassword.getText().equals(textBoxPassword.getText()) == false){
			check = false;
			alertText += "\n*Passwords are not equal";
		}
		
		//USERNAME
		
		
		if(checkBox.isChecked() == false){
			check = false;
			alertText += "\nCheckbox is not checked";
		}
		
		
		if(check == false)
			Window.alert(alertText);
		
		
		
		return check;
	}
	
	
}